//FULLY CONVERTED...UNTESTED

using System.Collections.Generic;
using System;
using UnityEngine;


public class ChargeWheel : ScriptableObject{
        
		public const int CHARGECAP = 5;
        public int[] charges;
        public enum chargeType{PASSION,ETHICS,DECEPTION,LOGIC};
        
        public ChargeWheel(){
                charges = new int[4];
                for(int i=0;i<charges.Length;i++) charges[i]=0;
        }
        
        public void destroyRandomCharge(){
			
			System.Random rand= new System.Random();
			List<int> chargelist = new List<int>();
			for(int i=0; i<4; i++){
				for(int j=0; j<charges[i]; j++){
					chargelist.Add(i);
				}
			}
			if (chargelist.Count > 0)
			{
				int index = rand.Next(chargelist.Count);
				charges[chargelist[index]]--;
			}
        }
        
        public void gainRandomCharge(){
			
			System.Random rand= new System.Random();
			int check = 0;
			for(int i=0; i< charges.Length; i++){
				if(charges[i] >= CHARGECAP) check++;
			}
			if(check >= 4) return;
			bool loop = true;
			do{
				int index= rand.Next(4);
				if(charges[index] < CHARGECAP){charges[index]++; loop=false;}
			}while(loop);
        }
        
        public int getCharge(chargeType charge){
			int result = 0;

			switch(charge){
			case chargeType.PASSION:
					result= charges[0];
					break;
			case chargeType.ETHICS:
					result= charges[1];
					break;
			case chargeType.DECEPTION:
					result= charges[2];
					break;
			case chargeType.LOGIC:
					result= charges[3];
					break;
			}
			
			return result;
        }
        
        public void spendCharge(chargeType charge){
            switch(charge){
            case chargeType.PASSION:
                    charges[0] -= 2;
                    break;
            case chargeType.ETHICS:
                    charges[1] -= 2;
                    break;
            case chargeType.DECEPTION:
                    charges[2] -= 2;
                    break;
            case chargeType.LOGIC:
                    charges[3] -= 2;
                    break;
            }
            
    }
        
        public void setCharge(chargeType charge, int newAmount){
                switch(charge){
                case chargeType.PASSION:
                        charges[0]=newAmount;
                        break;
                case chargeType.ETHICS:
                        charges[1]=newAmount;
                        break;
                case chargeType.DECEPTION:
                        charges[2]=newAmount;
                        break;
                case chargeType.LOGIC:
                        charges[3]=newAmount;
                        break;
                }
        }
        
        public void incrementCharge(chargeType charge){
                switch(charge){
                case chargeType.PASSION:
                        charges[0]++;
                        if(charges[0]>CHARGECAP) charges[0]=CHARGECAP;
                        break;
                case chargeType.ETHICS:
                        charges[1]++;
                        if(charges[1]>CHARGECAP) charges[1]=CHARGECAP;
                        break;
                case chargeType.DECEPTION:
                        charges[2]++;
                        if(charges[2]>CHARGECAP) charges[2]=CHARGECAP;
                        break;
                case chargeType.LOGIC:
                        charges[3]++;
                        if(charges[3]>CHARGECAP) charges[3]=CHARGECAP;
                        break;
                }
        }
        
        public void reset()
        {
        	for(int i=0;i<charges.Length;i++) charges[i]=0;
        }
}